package com.kotlin

/**
 * 测试枚举类
 *
 * @author huan.fu
 * @date 2019-03-10 - 21:23
 */
enum class LogLevel(val status: Int, val desc: String) {
    ERROR(1, "error"){
        override fun execute() {
            println("ERROR.execute")
        }
    },
    WARN(2, "warn") {
        override fun execute() {
            println("WARN.execute")
        }
    },
    INFO(3, "info") {
        override fun execute() {
            println("INFO.execute")
        }
    },
    DEBUG(4, "debug") {
        override fun execute() {
            println("DEBUG.execute")
        }
    },
    VERBOSE(5, "verbose") {
        override fun execute() {
            println("VERBOSE.execute")
        }
    };

    companion object {
        fun getLevel(level: Int): LogLevel? {
            return values().filter { it.status == level }.stream().findFirst().orElse(null)
        }
    }

    abstract fun execute()
}

fun main() {
    println(LogLevel.getLevel(1))
    println(LogLevel.getLevel(8))
}